﻿jQuery.support.cors = true;
$(document).ready(function () {
    $('#defaultForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            UserName: {
                validators: {
                    notEmpty: {
                        message: '请输入您的账号'
                    },
                    stringLength: {
                        min: 5,
                        max: 30,
                        message: '您的账号必须在 5 个字符 或 30 字符之间'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: '您的账号格式不正确'
                    }
                }
            },
            PassWord: {
                validators: {
                    notEmpty: {
                        message: '请输入您的密码'
                    },
                    stringLength: {
                        min: 6,
                        max: 12,
                        message: '密码必须在 6 个字符 或 12 字符之间'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: '您的账号格式不正确'
                    }
                }
            }
        }
    }).on('success.form.bv', function (e) {
        // Prevent form submission
        e.preventDefault();

        // Get the form instance
        var $form = $(e.target);

        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
        // Use Ajax to submit form data
        //console.log($form.serialize());
        //$.post($form.attr('action'), $form.serialize(), function (result) {
        //    console.log(result);
        //}, 'json');
        $.ajax({
            type: "POST",
            url: $form.attr('action'),
            data: $form.serialize(),
            success: function (data, status) {
                if (data.Code == 200) {
                    location.href = "/Manage/Home/Main";
                }
            },
            error: function (e) {
                
            },
            complete: function () {

            }

        });
    });
});